home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus 2000 #4 / Amiga Plus CD - 2000 - No. 4.iso / Tools / Misc / bgui / Examples / Source / Colors.c < prev    next >
C/C++ Source or Header  |  2000-05-09  |  8KB  |  162 lines

  1. /*
  2.  * @(#) $Header: /cvsroot/bgui/examples/Colors.c,v 41.11 2000/05/09 20:33:25 mlemos Exp $
  3.  *
  4.  * Colors.c
  5.  *
  6.  * (C) Copyright 1998 Manuel Lemos.
  7.  * (C) Copyright 1995 Jaba Development.
  8.  * (C) Copyright 1995 Jan van den Baard.
  9.  * All Rights Reserved.
  10.  *
  11.  * $Log: Colors.c,v $
  12.  * Revision 41.11  2000/05/09 20:33:25  mlemos
  13.  * Bumped to revision 41.11
  14.  *
  15.  * Revision 1.2  2000/05/09 19:58:45  mlemos
  16.  * Merged with the branch Manuel_Lemos_fixes.
  17.  *
  18.  * Revision 1.1.2.1  1998/02/28 17:45:01  mlemos
  19.  * Ian sources
  20.  *
  21.  *
  22.  */
  23.  
  24. /* Execute me to compile with DICE V3.0
  25. dcc Colors.c -mi -ms -mRR -proto -lbgui
  26. quit
  27. */
  28.  
  29. #include "DemoCode.h"
  30.  
  31. /*
  32. **      Object ID's.
  33. **/
  34. #define ID_ALT                  1
  35. #define ID_QUIT                 2
  36.  
  37. VOID StartDemo( void )
  38. {
  39.         struct Window           *window;
  40.         Object                  *WO_Window, *GO_Quit, *GO_B[ 2 ], *GO_Alt;
  41.         ULONG                    signal, rc, tmp = 0, a;
  42.         BOOL                     running = TRUE;
  43.  
  44.         /*
  45.          *      Create the window object.
  46.          */
  47.         WO_Window = WindowObject,
  48.                 WINDOW_Title,           "Colors Demo",
  49.                 WINDOW_AutoAspect,      TRUE,
  50.                 WINDOW_SmartRefresh,    TRUE,
  51.                 WINDOW_RMBTrap,         TRUE,
  52.                 WINDOW_MasterGroup,
  53.                         VGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), GROUP_BackFill, SHINE_RASTER,
  54.                                 StartMember,
  55.                                         InfoFixed( NULL, ISEQ_C "This small demo shows you how you can\n"
  56.                                                          "change the background and label colors\n"
  57.                                                          "of an object on the fly.\n\n"
  58.                                                          "As you can see the colors of the below buttons\n"
  59.                                                          "are normal but when the " ISEQ_B "Alternate" ISEQ_N " checkbox\n"
  60.                                                          "is selected the colors are changed.",
  61.                                                          NULL, 7 ),
  62.                                 EndMember,
  63.                                 StartMember,
  64.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
  65.                                                 StartMember, GO_B[ 0 ] = Button( "Colors", 0 ), EndMember,
  66.                                                 StartMember, GO_B[ 1 ] = Button( "Demo",   0 ), EndMember,
  67.                                         EndObject, FixMinHeight,
  68.                                 EndMember,
  69.                                 StartMember,
  70.                                         HGroupObject, HOffset( 4 ), VOffset( 4 ), Spacing( 4 ), FRM_Type, FRTYPE_BUTTON, FRM_Recessed, TRUE,
  71.                                                 VarSpace( DEFAULT_WEIGHT ),
  72.                                                 StartMember, GO_Alt = KeyCheckBox( "_Alternate", FALSE, ID_ALT ), EndMember,
  73.                                                 VarSpace( DEFAULT_WEIGHT ),
  74.                                         EndObject, FixMinHeight,
  75.                                 EndMember,
  76.                                 StartMember,
  77.                                         HGroupObject,
  78.                                                 VarSpace( DEFAULT_WEIGHT ),
  79.                                                 StartMember, GO_Quit = KeyButton( "_Quit", ID_QUIT ), EndMember,
  80.                                                 VarSpace( DEFAULT_WEIGHT ),
  81.                                         EndObject, FixMinHeight,
  82.                                 EndMember,
  83.                         EndObject,
  84.         EndObject;
  85.  
  86.         /*
  87.         **      Object created OK?
  88.         **/
  89.         if ( WO_Window ) {
  90.                 /*
  91.                 **      Assign the keys to the buttons.
  92.                 **/
  93.                 tmp += GadgetKey( WO_Window, GO_Quit,  "q" );
  94.                 tmp += GadgetKey( WO_Window, GO_Alt,   "a" );
  95.                 /*
  96.                 **      OK?
  97.                 **/
  98.                 if ( tmp == 2 ) {
  99.                         /*
  100.                         **      try to open the window.
  101.                         **/
  102.                         if ( window = WindowOpen( WO_Window )) {
  103.                                 /*
  104.                                 **      Obtain it's wait mask.
  105.                                 **/
  106.                                 GetAttr( WINDOW_SigMask, WO_Window, &signal );
  107.                                 /*
  108.                                 **      Event loop...
  109.                                 **/
  110.                                 do {
  111.                                         Wait( signal );
  112.                                         /*
  113.                                         **      Handle events.
  114.                                         **/
  115.                                         while (( rc = HandleEvent( WO_Window )) != WMHI_NOMORE ) {
  116.                                                 /*
  117.                                                 **      Evaluate return code.
  118.                                                 **/
  119.                                                 switch ( rc ) {
  120.  
  121.                                                         case    WMHI_CLOSEWINDOW:
  122.                                                         case    ID_QUIT:
  123.                                                                 running = FALSE;
  124.                                                                 break;
  125.  
  126.                                                         case    ID_ALT:
  127.                                                                 /*
  128.                                                                  *      When the object is selected we use
  129.                                                                  *      alternate coloring on the objects.
  130.                                                                  *      If not we revert to default coloring.
  131.                                                                  */
  132.                                                                 GetAttr( GA_Selected, GO_Alt, &tmp );
  133.                                                                 /*
  134.                                                                  *      Setup the colors on the buttons.
  135.                                                                  */
  136.                                                                 for ( a = 0; a < 2; a++ )
  137.                                                                         SetGadgetAttrs(( struct Gadget * )GO_B[ a ], window, NULL,
  138.                                                                                 FRM_BackDriPen,                 tmp ? TEXTPEN  : (ULONG)~0,
  139.                                                                                 FRM_SelectedBackDriPen,         tmp ? SHINEPEN : (ULONG)~0,
  140.                                                                                 LAB_DriPen,                     tmp ? SHINEPEN : (ULONG)~0,
  141.                                                                                 LAB_SelectedDriPen,             tmp ? TEXTPEN  : (ULONG)~0,
  142.                                                                                 TAG_END );
  143.                                                                 break;
  144.                                                 }
  145.                                         }
  146.                                 } while ( running );
  147.                         } else
  148.                                 Tell( "Could not open the window\n" );
  149.                 } else
  150.                         Tell( "Could not assign gadget keys\n" );
  151.                 /*
  152.                 **      Disposing of the window object will
  153.                 **      also close the window if it is
  154.                 **      already opened and it will dispose of
  155.                 **      all objects attached to it.
  156.                 **/
  157.                 DisposeObject( WO_Window );
  158.         } else
  159.                 Tell( "Could not create the window object\n" );
  160. }
  161.  
  162.